//
//  CurrencyType.m
//  MarketDataColloctor
//
//  Created by jiro on 10/03/11.
//  Copyright 2010 jiro music. All rights reserved.
//

#import "CurrencyType.h"
#import "DbConstants.h"

NSString* CurrencyType::tableName()
{
	return kText_CurrencyTypeTable;
}

NSString* CurrencyType::queryCreateTable()
{
	NSString* s = [ NSString stringWithFormat:
		@"create table %@ ( %@ %@, %@ %@, %@( %@ ) );",
		kText_CurrencyTypeTable,
		kText_Code, kText_Text,
		kText_Name, kText_Text,
		kText_PrimaryKey, kText_Code
	];
	return s;
}

NSString* CurrencyType::querySelectAll( const std::vector< ClauseNode >& clauses )
{
	NSString* s = DbTableEntry::querySelectAll( CurrencyType::tableName(), clauses );
	return s;
}

NSString* CurrencyType::querySelect( const std::vector< FieldNode >& fieldNodes, const std::vector< ClauseNode >& clauses )
{
	NSString* s = DbTableEntry::querySelect( fieldNodes, CurrencyType::tableName(), clauses );
	return s;
}

NSString* CurrencyType::queryInsertInitialValues()
{
	NSString* codes[] = {
		@"USD",		@"GBP",		@"INR",		@"IDR",		@"ECS",		@"EGP",		@"AUD",		@"CAD",		@"KRW",
		@"KWD",		@"COP",		@"SAR",		@"SGD",		@"CHF",		@"SEK",		@"THB",		@"TWD",		@"CNY",
		@"CLP",		@"DKK",		@"TRY",		@"JPY",		@"NZD",		@"NOK",		@"PYG",		@"PHP",		@"BRL",
		@"VEF",		@"PEN",		@"HKD",		@"MYR",		@"ZAR",		@"MXN",		@"AED",		@"EUR",		@"JOD",
		@"RON",		@"LBP",		@"RUB",	};
	NSMutableString* s = [ NSMutableString string ];
	for ( int i = 0, count = sizeof( codes ) / sizeof( NSString* ); i < count; i++ )
	{
		if ( i != 0 )
		{
			[ s appendString: @", " ];
		}
		[ s appendFormat: @"( '%@' )", codes[ i ] ];
	}
	return s;
}

CurrencyType::CurrencyType()
{}

CurrencyType::CurrencyType( std::vector< const char* > values )
{
	code = [ NSString stringWithCString: values[ 0 ] encoding: NSUTF8StringEncoding ];
	name = [ NSString stringWithCString: values[ 1 ] encoding: NSUTF8StringEncoding ];
}

NSString* CurrencyType::queryInsert() const
{
	return [ NSString stringWithFormat: @"insert into %@ values %@;",
		CurrencyType::tableName(), queryInsertValue() ];
}

NSString* CurrencyType::queryInsertValue() const
{
	return [ NSString stringWithFormat: @"( '%@', '%@' )",
		code, name ];
}
